package top.laoliu.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import top.laoliu.pojo.Admin;
import top.laoliu.service.AdminService;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.List;

/**
 * @Author: acer
 * @Date: 2020/10/6 15:40
 * @Description:
 */
@Controller
@RequestMapping("/admin")
public class AdminController {
    @Autowired
    private AdminService adminService;

    @RequestMapping("/test")
    public void testAdmin(){
        System.out.println(adminService.getAllAdmins());
    }

    @RequestMapping("/testHtml")
    public String testAdmin2(Model model, HttpSession session){
//        List<Admin> admins = adminService.getAllAdmins();
//        model.addAttribute("admins",admins);
//        session.setAttribute("user","user123");
//        System.out.println(session.getAttribute("user"));
        return "userProfile";
    }

    @RequestMapping("/tt")
    @ResponseBody
    public List<Admin> test3(HttpSession session){
        List<Admin> admins = adminService.getAllAdmins();
        session.setAttribute("user","user123");
        return admins;
    }

    @GetMapping("/test4/{id}")
    @ResponseBody
    public String test4(@PathVariable String id){
        return id;
    }
}
